package com.young.android.business;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import com.young.android.dbreposit.SqliteHelper;
import com.young.android.entity.Item;

public class MainBusiness {
    
    /**
     * 载入配置
     * @return
     */
    public static void LoadConfig(Context acontext){
        SqliteHelper.setContext(acontext);
        SqliteHelper.OpenCfgDB();
        //载入
        //..
        
    }
    
    /**
     * 打开数据
     * 
     * @param acontext
     * @return
     */
    public static int OpenDB(Context acontext)
    {
      int ireturn = SqliteHelper.openRSSDB();
      return ireturn;
    }

    /**
     * 关闭数据库
     * 
     */
    public static void CloseDB()
    {
      SqliteHelper.close();
    }


    /**
     * 读取网络数据并添加到数据库
     * 
     * @param url
     * @return
     * @throws XmlPullParserException
     * @throws IOException
     */
    public static ArrayList<Item> getUrlFeed(String url) {
        XMLPullHandler pullHandler = null;
        try {
            pullHandler = new XMLPullHandler(url);
            pullHandler.processDocument();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return pullHandler.getFeed();

    }

}
